//
//  JiaoXueYiShangKeShiNextVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/5/13.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "JiaoXueYiShangKeShiNextVC.h"

@interface JiaoXueYiShangKeShiNextVC ()<KeChengNextNavSelectedDelegate,KeChengXueShengViewDelegate>

@end

@implementation JiaoXueYiShangKeShiNextVC
- (instancetype)initWithClassID:(NSString *)classID andLessonID:(NSString *)lessonID{
    if ([super init]) {
        self.classID = classID;
        self.lessonId = lessonID;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    self.mainw = MAINW;
    self.view.backgroundColor = MAINBACKCOLOR;
    _yiShangKeChengXueShengModelArray = [NSMutableArray new];
    [self.view addSubview:self.navView];
    [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    
    [self.view addSubview:self.keChengXueShengView];
    [self.keChengXueShengView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0).offset(-20);
        make.top.equalTo(@44);
        make.bottom.equalTo(@0).offset(0);
    }];
    
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView:) name:@"ChangeCellSpaNotice" object:nil];
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView:) name:@"TeachChangeNotice" object:nil];
    [self getKeChengXueSheng];
    
}
- (void)getKeChengXueSheng{
    [self getKeChengXueShengYiShangKeShiLisetRequest];
}
#pragma mark - 这个基本每个类都要用
//- (void)changeView:(NSNotification *)info{
//    int type = [[info.userInfo objectForKey:@"Type"] intValue];
//    _mainw = [PublickFunctionObject currentScreenSize:type];
//    NSLog(@"view宽度 %f",_mainw);
//    _navView.frame = CGRectMake(0, 0, _mainw, 44);
//    
//    //课程学生
//    _keChengXueShengView.frame = CGRectMake(0, 44, _mainw, self.view.frame.size.height-44);
//    _keChengXueShengView.mainw = _mainw;
//    [_keChengXueShengView.tableList reloadData];
//    
//}
- (KeChengNextNavView *)navView{
    if (!_navView) {
        KeChengNextNavView *topView = [[KeChengNextNavView alloc]init];
        topView.frame = CGRectMake(0, 0, _mainw, 44);
        topView.backgroundColor = self.view.backgroundColor;
        topView.delegate = self;
        [topView.jieYeButton setTitle:@"" forState:0];
        topView.jieYeButton.hidden = YES;
//        [topView.jieYeButton setTitleColor:TITLECOLOR forState:UIControlStateSelected];
        [topView.weiJieYeButton setTitleColor:SELECTEDCOLOR forState:UIControlStateNormal];
        topView.lineView.hidden = YES;
        _navView = topView;
    }
    return _navView;
}

- (void)addChildViewForDetailAndID:(NSString *)index{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    _xueShengDetailVC = [[XueShengXiangQingVC alloc]initWothStudentID:index];
    _xueShengDetailVC.view.backgroundColor = [UIColor whiteColor];
    _xueShengDetailVC.view.frame = CGRectMake(self.mainw, 0, self.mainw, APP_HEIGHT-84);
    [self.view addSubview:_xueShengDetailVC.view];
    [_xueShengDetailVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
- (KeChengXueShengView *)keChengXueShengView{
    if (!_keChengXueShengView) {
        KeChengXueShengView *view = [[KeChengXueShengView alloc]initWithClassID:self.classID andLessonID:self.lessonId WithFrame:CGRectMake(0,44, self.mainw,self.view.frame.size.height-44)];
        view.myDelagete = self;
        _keChengXueShengView = view;
    }
    return _keChengXueShengView;
}
- (void)addChildViewForDetail:(int)index{
    JiaoXueKeChengKeChengXueShengModel *model = _yiShangKeChengXueShengModelArray[index];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    _xueShengDetailVC = [[XueShengXiangQingVC alloc]initWothStudentID:model.studentId];
    _xueShengDetailVC.view.backgroundColor = [UIColor whiteColor];
    _xueShengDetailVC.view.frame = CGRectMake(self.mainw, 0, self.mainw, APP_HEIGHT);
    [self.view addSubview:_xueShengDetailVC.view];
    [_xueShengDetailVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
#pragma mark - 课时学生
- (void)leftButtonClick{
    
}
#pragma mark - 前往作业
- (void)rightButtonClick{
    //指定NAV到作业
    [[NSNotificationCenter defaultCenter]postNotificationName:@"TABBAR_GoZuoYe" object:nil userInfo:@{@"classId":self.lessonId,@"lessonId":self.lessonId}];
}
- (void)backClick{
    [UIView animateWithDuration:0.3 animations:^{
        //self.view.frame= CGRectMake(0, 0, self->_mainw, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        self.view = nil;
    }];
    
}
#pragma mark - 得到已上课时课程学生
- (void)getKeChengXueShengYiShangKeShiLisetRequest{
    NSDictionary *parama = @{@"lessonId":self.lessonId,
                             @"serial":@"",
                             @"name":@"",
                             @"status":@"",
                             @"tryStatus":@""};
    [MBProgressHUD mj_showMessage:nil toView:self.view];
    [SYRequestAPI sy_getLessonStudent:parama success:^(id  _Nonnull responseObject){
       // NSLog(@"教学-课程-已上课时-课程学生 %@",responseObject);
        [self->_yiShangKeChengXueShengModelArray removeAllObjects];
        NSArray *array = [responseObject objectForKey:@"data"];
        for (int i = 0; i<array.count; i++) {
            JiaoXueKeChengKeChengXueShengModel *model = [JiaoXueKeChengKeChengXueShengModel yy_modelWithJSON:array[i]];
            [self->_yiShangKeChengXueShengModelArray addObject:model];
        }
        self->_keChengXueShengView.dataArray = self->_yiShangKeChengXueShengModelArray;
        [self->_keChengXueShengView.tableList reloadData];
        [MBProgressHUD mj_hideHUDForView:self.view];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self.view];
    }];
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"TABBAR_GoZuoYe" object:nil];
}

@end
